from flask import Blueprint,jsonify,request,abort
from flask_restful import Api,Resource
from app.models import *
# main = Blueprint("main", __name__)
statistics = Api()
class Statistics1(Resource):
    def get(self):
        statistics = Statistics.query.all()
        return jsonify({"ab": list(map(con1, statistics))})
    def post(self):
        statistics_add = Statistics(
            request.json["teacher_intr"],
            request.json["trainess_intr"],
            request.json["agent_intr"]

        )
        db.session.add(statistics_add)
        db.session.commit()
        return jsonify({"statistics1": con1(statistics_add)}), 201
statistics.add_resource(Statistics1,'/statistics1/')

class Statistics2(Resource):
    def get(self,uid):
        statistics2 = Statistics.query.filter_by(id=uid).first()
        if statistics2 is None:
            abort(404)
        return jsonify({"statistics2": con1(statistics2)})
    def put(self,uid):
        statistics_update = Statistics.query.get(uid)
        statistics_update.teacher_intr = request.json.get("teacher_intr")
        statistics_update.trainess_intr = request.json.get("trainess_intr")
        statistics_update.agent_intr = request.json.get("agent_intr")
        db.session.add( statistics_update)
        db.session.commit()
        return jsonify({" statistics_update": con1( statistics_update)})
statistics.add_resource(Statistics2,'/statistics2/<int:uid>/')
